import moment from "moment"

const mixin = {
    data() {
        return {
            loadData: []
        }
    },
    methods: {
        //验证手机号
        validatePhone(phone) {
            let tel = /^[1]{1}[3,5,7,8]{1}[0-9]{9}$/;
            if (!tel.test(phone)) return true
        },
        //密码输入限制（英文、数字、特殊字符）
        validateInput(val) {
            // var reg = /^(?=.*[a-zA-Z])(?=.*\d)|(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,.\/]).{8,20}$/;
            let reg = /^(?![A-Z]+$)(?![a-z]+$)(?!\d+$)(?![\W_]+$)\S{8,20}$/
            if (!reg.test(val)) return true
        },
        //名字限制（中文、英文、数字）
        validateName(val) {
            let reg = /^([a-zA-Z0-9\u4e00-\u9fa5])|(?=[a-zA-Z0-9\u4e00-\u9fa5])([()（）])|([()（）].[a-zA-Z0-9\u4e00-\u9fa5])(?!.*?_$)$/
            if (!reg.test(val)) return true
        },
        //设置字符串长度
        setString(val, len) {
            if (val.length > len) return val.substring(0, len) + '...'
            return val
        },

        //成功提示
        success: function(message, duration = 1500) {
            this.$toast.success(message, duration);
        },
        //失败提示
        fail: function(message, duration = 1500) {
            this.$toast.fail(message, duration);
        },
        load: function() {
            this.$toast.loading()
        },
        clear: function() {
            this.$toast.clear()

        },
        //计算价格
        computePrice(price) {
            if (price == 0) return parseInt(price / 100).toFixed(2)
            return parseInt((price / 100).toFixed(2))
        },

        //上拉刷新
        pubilcInitDataList(apiConst, paramsObj) {
            this.$store.dispatch(types[apiConst], paramsObj).then(res => {
                if (res.code !== 0) return
                let data = res.data
                this.loadData = this.loadData.concat(data);
                console.log(this.loadData)
                this.params.offset = this.loadData.length;
                this.$refs.scroll.finish(data.length, paramsObj.len);
            })
        },
        //设置右边按钮的状态
        setRightStatus() {

        },
        //更多加载
        pubilcLoadDataList() {

        },
    },
    filters: {
        // hideTel: function (tel) {
        //     if (!tel) return "";
        //     return tel.substr(0, 3) + "****" + tel.substr(7);
        // },
        // setActivityTime: function (val) {
        //     return moment(val).calendar();
        // }
        transformTimestamp: function(timestamp) {
            return moment(timestamp).format('YYYY-MM-DD hh:mm:ss')
        },
        momentDay: function(timestamp) {
            return moment(timestamp).dayOfYear()
        }
    },

}
export default mixin